<script language="javascript" type="text/javascript" charset="utf-8">
function sendBookingRequest() {
	var checkin = document.getElementById("checkin");
	var checkout = document.getElementById("checkout");
	var no_nights = document.getElementById("no_nights");
	var roomcat = document.getElementById("cmbRoomCat");
	var roomtype = document.getElementById("cmbRoomType");
	var rooms = document.getElementById("no_rooms");
	var adult = document.getElementById("adult");
	var children = document.getElementById("children");
        var infants = document.getElementById("infants");
	var additional_info = document.getElementById("additional_info");
	var transfer_option = document.getElementById("transfer_option");
        var transfertype = document.getElementById("transfertype");
	var fullname = document.getElementById("fullname");
	var email = document.getElementById("email");
	var telephone = document.getElementById("telephone");
	var address = document.getElementById("address");
	var country = document.getElementById("country");
	var comments = document.getElementById("comments");
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var hotel_id = document.getElementById("txtHotelId").value;
	if(checkin.value == "") {
		alert("Please select the check-in date");
		checkin.focus();
		return false;
	} else if(checkout.value == "") {
		alert("Please select the check-out date");
		checkout.focus();
		return false;
	} else if(no_nights.value == "") {
		alert("Please enter number of nights you decide to stay in the hotel");	
		no_nights.focus();
		return false;
	} else if(rooms.value == "") {
		alert("Please enter number of rooms you want to reserve");
		rooms.focus();
		return false;	
	} else if((document.getElementById("hotel_country_booking") != undefined && document.getElementById("hotel_country_booking") != null) && (document.getElementById("hotel_country_booking").selectedIndex == 0)) {            
            alert("Please select a Country");
            document.getElementById("hotel_country_booking").focus();
            return false;            
	} else if((document.getElementById("hotel_city_booking") != undefined && document.getElementById("hotel_city_booking") != null) && (document.getElementById("hotel_city_booking").selectedIndex == 0)) {     
            alert("Please select a City");
            document.getElementById("hotel_city_booking").focus();
            return false;            
	} else if((document.getElementById("cmbhotel_booking") != undefined && document.getElementById("cmbhotel_booking") != null) && (document.getElementById("cmbhotel_booking").selectedIndex == 0)) {     
            alert("Please select a Hotel");
            document.getElementById("cmbhotel_booking").focus();
            return false;            
	} else if(roomcat.selectedIndex == 0) {
		alert("Please select a room category");
		roomcat.focus();
		return false;
	} else if(roomtype.selectedIndex == 0) {
		alert("Please select a room type");
                rooms.focus();
		return false;
	} else if(adult.selectedIndex == 0) {
		alert("Please select any number of adults");
		adult.focus();
		return false;
	}else if($('#transfer_option').attr('checked')==true && transfertype.value=="") {

		alert("Please select transfer type");
		transfertype.focus();
		return false;
               
	}   else if(fullname.value == "") {
		alert("Please enter your name");
		fullname.focus();
		return false;
	} else if(email.value == "") {
		alert("Please enter your email address");
		return false;
	} else if(email.value != "" && reg.test(email.value) == false) {
        alert("Invalid email address");
        email.focus();
        return false;
    } /*else if(address.value == "") {
    	alert("Please enter your valid postal address");
        address.focus();
        return false;
    }*/ else if(country.selectedIndex == 0) {
    	alert("Please select your country");
        country.focus();
        return false;
    } else {
        if((document.getElementById("cmbhotel_booking") != undefined && document.getElementById("cmbhotel_booking") != null) && (document.getElementById("cmbhotel_booking").selectedIndex != 0)) {     
            hotel_id=document.getElementById("cmbhotel_booking").value;            
        }
        var module = "";
        var module_val= "";
        if(document.getElementById("module") != undefined && document.getElementById("module") != null){
            module = document.getElementById('module').value
            module_val= document.getElementById('module_val').value
        }
    	$.ajax ({
	    	type: "POST",
	    	data: ({hotel_id:hotel_id, checkin: checkin.value, checkout: checkout.value,infants:infants.value, no_nights: no_nights.value, rooms: rooms.value, roomcat: roomcat.value, roomtype: roomtype.value, adult: adult.value, children:children.value, additional_info: additional_info.value, transfer_option: transfer_option.value,transfertype:transfertype.value, fullname: fullname.value, email: email.value, telephone: telephone.value, address: address.value, country: country.value, comments: comments.value, module: module, module_val: module_val}),
	    	url: "/default/hotel/sendbookingrequest/",
	    	success: function(data){
	    	   alert(data);
	    	   loadPage("/default/hotel/view/");	
	    	}
		});	
    }	 
}

function validatebookinform()
{
	var sender_name = document.getElementById("sender_name");
	var sender_email =  document.getElementById("sender_email");
	var country = document.getElementById("cmbCountry");
	var city = document.getElementById("cmbCity");
	var hotel = document.getElementById("cmbHotel");
	var checkin = document.getElementById("date18");
	var checkout = document.getElementById("date10");
	var adults = document.getElementById("adults");
	var children = document.getElementById("children");
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var msg = '';
	if(sender_name.value == "") {
		alert("<?php echo $this->translate('%Please enter your name','alerts'); ?>");
		sender_name.focus();
		return false;
	} else if(sender_email.value == "") {
		alert("<?php echo $this->translate('%Please enter your email address','alerts'); ?>");
		sender_email.focus();
		return false;
	} else if(sender_email.value != "" && reg.test(sender_email.value) == false) {
        alert("<?php echo $this->translate('%Invalid email address','alerts'); ?>");
        sender_email.focus();
        return false;
    } else if(country.selectedIndex == 0) {
    	alert("<?php echo $this->translate('%Please select your country','alerts'); ?>");
    	country.focus();
    	return false;
    } else if(city.selectedIndex == 0) {
    	alert("<?php echo $this->translate('%Please select your city','alerts'); ?>");
    	city.focus();
    	return false;
    } else if(hotel.selectedIndex == 0) {
    	alert("<?php echo $this->translate('%Please select a hotel','alerts'); ?>");
    	hotel.focus();
    	return false;
    } else if(checkin.value == "") {
    	alert("<?php echo $this->translate('%Please select a date you suppose to checked in','alerts'); ?>");
    	checkin.focus();
    	return false;
    } else if(checkout.value == "") {
    	alert("<?php echo $this->translate('%Please select a date you suppose to checked out','alerts'); ?>");
    	checkout.focus();
    	return false;
    } else {
    	return true;
    }
}

function doQuickSearch() {
        var res_booking=(document.getElementById("res_booking")==null || document.getElementById("res_booking")==undefined)?"0":document.getElementById("res_booking").value;
        var country ="";
	var city = "";
	var hotel = "";
        
        if (res_booking!="1"){
	 country = document.getElementById("hotel_country");
	 city = document.getElementById("hotel_city");
	 hotel = document.getElementById("cmbhotel");
        }else{
         country = document.getElementById("hotel_country_booking");
	 city = document.getElementById("hotel_city_booking");
	 hotel = document.getElementById("cmbhotel_booking");
        }
	var msg = "";	
	
	if(country.selectedIndex == 0) {
		alert("<?php echo $this->translate('%Please select country','alerts'); ?>");
		country.focus();
		return false;
	} else if(city.selectedIndex == 0) {
		alert("<?php echo $this->translate('%Please select city','alerts'); ?>");
		city.focus();
		return false;
	} else if(hotel.selectedIndex == 0) {
		alert("<?php echo $this->translate('%Please select a hotel','alerts'); ?>");
		hotel.focus();
		return false;
	} else {
                if(res_booking!="1"){
                    $.ajax ({
                    type: "POST",
                    data: ({hotelid: hotel.value, req: 'quicksearch'}),
                    url: "/hotel/booking/",
                    success: function(data){
                    //alert(data);
                    //loadPage("/hotel/details/hotelid/"+hotel.value);                   
                    $("#mid-content").html(data);
                    }
                    });	
                }else{
                window.location='/index/booking/hotelid/'+hotel.value;
                /*$.ajax ({
                    type: "POST",
                    data: ({hotelid: hotel.value, req: 'quicksearch'}),
                    url: "/index/booking/",
                    success: function(data){
                    //alert(data);
                    //loadPage("/hotel/details/hotelid/"+hotel.value);                   
                    $("#mid-content").html(data);
                    }
                    });	*/
                }
	}
}

function viewHotelDetails(hotel_id) {
	$.ajax ({
    	type: "POST",
    	data: ({hotelid: hotel_id}),
    	url: "/hotel/details/",
    	success: function(data){
    	   $("#mid-content").html(data);
    	}
	});	
}

function subscribeNewsletter(lang)
{
	var nletter_email = $("#nletter_email");
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(nletter_email.val() == "") {
		alert("<?php echo $this->translate('%Please enter your email address', 'alerts'); ?>");
		nletter_email.focus();
		return false;
	} else if(nletter_email.val() != "" && reg.test(nletter_email.val()) == false) {
		alert("<?php echo $this->translate('%Invalid email address','alerts'); ?>");
		nletter_email.focus();
		return false;
	} else {
		$.ajax ({
	    	type: "POST",
	    	data: ({nletter_email: nletter_email.val(), lang: lang}),
	    	url: "/newsletter/subscribe/",
	    	success: function(data){
	    	   alert(data);
	    	}
		});
	}
}
</script>